import { Injectable } from '@angular/core';
import { Hero } from './hero';
import { HEROES } from './mock-heroes';
import { Observable } from 'rxjs';
import { of } from 'rxjs';
import { MessageService } from './message.service';

@Injectable({
  providedIn: 'root'
})
export class HeroService {

  constructor(private messageService: MessageService) { }


  getHeroes(): Observable<Hero[]>{
    this.messageService.add('HeroService: 获取数据集合');
    return  of (HEROES);
  }

  getHero(id: number): Observable<Hero>{
    this.messageService.add(`HeroService: 获取数据集合 id=${id}`);
    return of(HEROES.find(hero=> hero.id === id));
  }
}
